<#cenluan title="蹦跶详情" menu="tweet" validate="true">
<ol class="breadcrumb mb20">
	<li><a href="/tweet">蹦跶</a></li>
	<li class="active">详情</li>
</ol>
<div class="row">
	<div class="col-md-6">
	<div class="media">
		<a class="media-left" href="javascript:;">
			<img src="${tweet.creater.avatarUrl}" class="avatar-md img-rounded">
		</a>
		<div class="media-body">
			<p>${tweet.creater.html}</p>
				<p>${tweet.content}</p>
				<%if(tweet.photoCount>0){%>
				<div class="mb10">
					<%for(photo in tweet.photoList){%>
						<a href="javascript:showDialog('/tweet/photo/show/${photo.id}');">
							<img src="${photo.url}@!tweet-photo-thum">
						</a>
					<%}%>
				</div>
				<%}%>
				<p class="small text-muted">
					${tweet.createTime,prettyTime}
					<%if(admin||session.user.id==tweet.createrId){%>
					&nbsp;&nbsp;<a href="javascript:;" id="btn-del">删除</a>
					<script>
						$(function(){
							$("#btn-del").click(function(){
								if(!confirm("一旦删除将无法恢复，确定要删除这条信息吗？")){
									return;
								}
								$.getJSON("/tweet/delete/${tweet.id}",function(json){
									if(json.ok){
										location="/tweet";
									}else{
										alert(json.msg);
									}
								});
							});
						});
					</script>
					<%}%>
				</p>
		</div>
	</div>
	<!-- 评论表单 -->
	<form action="/tweet/comment/save" id="commentForm">
		<input type="hidden" name="tweetId" value="${tweet.id}">
		<div class="form-group">
			<textarea rows="3" class="form-control" name="content" placeholder="说点什么吧" id="comment-content"
			 maxlength="200" minlength="1" required></textarea>
		</div>
		<div class="form-group row">
			<div class="col-md-7 text-right col-sm-8 col-xs-8">
				<label class="checkbox">
					<input type="checkbox" name="showLog" value="true" checked="checked">
					同时在我的动态中显示
				</label>
			</div>
			<div class="col-md-5 col-sm-4 col-xs-4">
				<button class="btn btn-primary btn-block" type="submit">提交</button>
			</div>
		</div>		
	</form>
	<!-- 评论列表 -->
	<hr class="dashed">
	<%for(comment in page.list){%>
	<div class="media">
		<a class="media-left" href="/user/show/${comment.createrId}">
			<img src="${comment.creater.avatarUrl}" class="avatar-md img-rounded">
		</a>
		<div class="media-body">
			<p>${comment.creater.html}</p>
			<p>${comment.content}</p>
			<div class="clearfix">
				<div class="pull-left text-muted">${comment.createTime,prettyTime}</div>
				<div class="pull-right">
						<%if(admin||session.user.id==tweet.createrId||session.user.id==comment.createrId){%>
							<a class="btn-del-comment" href="javascript:;" data-id="${comment.id}">删除</a>&nbsp;&nbsp;
						<%}%>
						<a class="btn-rpl" data-name="${comment.creater.nickname}" href="javascript:;">回复</a>
				</div>
			</div>
		</div>
	</div>
	<%if(!commentLP.last){%>
		<hr class="dashed">
	<%}%>
	<%}elsefor{%>
		无可显示数据
	<%}%>
	${pageLink}
	</div><!-- col-md-6 -->
</div><!-- row -->
<script>
$(function(){
	//评论表单
	$("#commentForm").validate({
		submitHandler:function(form){
			$(form).find(":submit").button("loading");
			$(form).ajaxSubmit(function(json){
				$(form).find(":submit").button("reset");
				$(form).resetForm();
				if(!json.ok){
					alert(json.msg);
					return
				}
				$.get("/tweet/comment/show/"+json.id,function(data){
					$(form).after(data);
				},"html");
			});
		}
	});
	//回复
	$(".container").on("click",".btn-rpl",function(){
		var content = $("#comment-content");
		content.val(content.val()+"@"+$(this).data("name")+",");
	});
	//删除评论
	$(".container").on("click",".btn-del-comment",function(){
		if(!confirm("确定要删除此评论吗？")){
			return;
		}
		var id = $(this).data("id");
		$.getJSON("/tweet/comment/delete/"+id,function(json){
			if(!json.ok){
				alert(json.msg);
				return;
			}
			$("#comment-"+id).prev("hr").remove();
			$("#comment-"+id).remove();
			if(!$(".table-comment").length){
				location="/tweet/show/${tweet.id}";
			}
		});
	});
});
</script>
</#cenluan>